import {
  getSalesOrderList as getSalesOrderList,
  getDeliveryMethodList as getDeliveryMethodList,
} from "@/api/order/mesProdOrderPlan";
import { popover } from "@/utils/judge";
export const mesSalesOrderDialog = {
  data() {
    return {
      mesSalesOrderDialogVisible: false, //表格弹框隐藏显示
      getSalesOrderList, // 获取弹框数据接口
      hasMesSalesOrderFooter: true, // 是否需要底部按钮默认true
      mesSalesOrderSearchDialog: {
        inline: true,
        formDesc: {
          // saleCode: {
          //   type: 'input',
          //   label: '销售订单编码',
          // },
          salesOrderCode: {
            type: "input",
            label: $i18n.t("mesProdOrderPlan.salesOrderCode"),
            layout: 12,
          },

          // orderStatus: {
          //   type: 'select',
          //   label: '订单状态',
          //   layout: 8,
          //   prop: {
          //     value: "value",
          //     text: "description",
          //   },
          //   options: async (data) => {
          //     const list = await getOrderStatusList()
          //     return list.data.result
          //   },
          // },
          // lineName: {
          //   type: 'input',
          //   label: '线体名称',
          // },
        },
      },
      mesSalesOrderDialogColumn3: [
        {
          type: "selection",
          fixed: "left",
        },
        {
          type: "index",
          label: $i18n.t("common.order"),
          width: 60,
          fixed: "left",
        },
        // {
        //   prop: "factoryCode",
        //   label: "工厂编码",
        //   minWidth: 120,
        //   showOverflowTooltip: true,
        // },
        {
          prop: "salesOrderCode",
          label: $i18n.t("mesProdOrderPlan.salesOrderCode"),
          minWidth: "140",
        },
        {
          prop: "customerCode",
          label: $i18n.t("mesProdOrderPlan.customerCode"),
          minWidth: "120",
        },
        {
          prop: "customerName",
          label: $i18n.t("mesProdOrderPlan.customerName"),
          minWidth: "180",

          render: (h, scope) => {
            return popover(scope.row.customerName, h);
          },
        },
        {
          prop: "telephone",
          label: $i18n.t("mesProdOrderPlan.telephone"),
          minWidth: "140",
        },
        {
          prop: "deliveryMethod",
          label: $i18n.t("mesProdOrderPlan.deliveryMethod"),
          minWidth: "120",

          optionProp: {
            value: "value",
            label: "description",
          },
          option: async (data) => {
            const list = await getDeliveryMethodList();
            return list.data.result;
          },
        },
        {
          prop: "deliveryAddress",
          label: $i18n.t("mesProdOrderPlan.deliveryAddress"),
          minWidth: "120",

          render: (h, scope) => {
            return popover(scope.row.deliveryAddress, h);
          },
        },
        {
          prop: "customerOrderCode",
          label: $i18n.t("mesProdOrderPlan.customerOrderCode"),
          minWidth: "120",
        },
        {
          prop: "planDeliveryDate",
          label: $i18n.t("mesProdOrderPlan.planDeliveryDate"),
          minWidth: "120",
        },
        // {
        //   prop: "remark",
        //   label: "备注",
        //   width: "120",
        //   showOverflowTooltip: true,
        // },
        {
          prop: "createByName",
          label: $i18n.t("common.createByName"),
          width: "130",
        },
        {
          prop: "createTime",
          label: $i18n.t("common.createTime"),
          width: "170",
          // showOverflowTooltip: true,
        },
        {
          prop: "updateByName",
          label: $i18n.t("common.updateByName"),
          width: "130",
        },
        {
          prop: "updateTime",
          label: $i18n.t("common.updateTime"),
          width: "170",
          // showOverflowTooltip: true,
        },
      ],
    };
  },
  methods: {
    // 弹框表格，双击表格，或者点击确定 返回选中数据
    getSelectMesSalesOrder1(data) {
      // 调试完成记得删除控制台打印
      // console.log("选中数据", data);
      // 这里可以自定义返回字段信息
      // 第一个入参为当前表单绑定的对象，第二个入参为要修改的字段名，第三个入参为选中数据中相应信息
      const planDeliveryDate = data[0].planDeliveryDate;
      const { planEndDate } = this.formDataDialog;
      this.$set(this.formDataDialog, "saleCode", data[0].salesOrderCode);
      //交付日期用来判断是否大于结束时间
      this.$set(this.formDataDialog, "planDeliveryDate", planDeliveryDate);

      if (planDeliveryDate && planEndDate) {
        if (
          new Date(planEndDate).getTime() > new Date(planDeliveryDate).getTime()
        ) {
          this.$message.error(
            `${$i18n.t("mesProdOrderPlan.msg12")}${planDeliveryDate}`
          );
          this.$set(this.formDataDialog, "planEndDate", null);
        }
      }
      this.getSalesDetail(data[0].salesOrderCode);
    },
  },
};
